class EventCommentsController < ApplicationController
  layout 'general'
  before_filter :login_required
  
  def create
    @event = Event.find(params[:event_id])
    @comment = EventComment.new(params[:comment])
    @comment.user = current_user
    @comment.event = @event
    @comment.save!
    flash[:notice] = "您刚刚发表了一个留言"
    redirect_back_or_default(event_path(@event))
  end
  
  def edit
    @event = Event.find(params[:event_id])
    @comment = EventComment.find(params[:id])
  end
  
  def update
    @event = Event.find(params[:event_id])
    @comment = EventComment.find(params[:id])
    @comment.update_attributes!(params[:comment])
    flash[:notice] = "您刚修改了您在#{@event.title}活动的留言"
    redirect_back_or_default(event_path(@event))
  end
  
  def destroy
    @event = Event.find(params[:event_id])
    @comment = EventComment.find(params[:id])
    @comment.destroy
    flash[:notice] = "您删除了自己在#{@event.title}的留言"
    redirect_back_or_default(event_path(@event))
  end
end
